package com.ruoyi.apm.model;

import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.exception.ServiceException;
import org.quartz.CronExpression;

/**
 * @author: youguoen
 * Date: 2023/12/27
 */
public class DockDataConfig {

    private Integer id;

    private String tableName;

    private String dataSource = DataSourceType.SLAVE.name();

    private String mappingRelation;

    private Integer fieldUpper;

    private Integer batchLimit;

    private Integer isWhile;

    private String whileRule;

    private Integer isClean;

    private String cleanRule;

    private String cron;

    private String guid;

    public String getDataSource() {
        return dataSource;
    }

    public void setDataSource(String dataSource) {
        this.dataSource = dataSource;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getMappingRelation() {
        return mappingRelation;
    }

    public void setMappingRelation(String mappingRelation) {
        this.mappingRelation = mappingRelation;
    }

    public Integer getBatchLimit() {
        return batchLimit;
    }

    public void setBatchLimit(Integer batchLimit) {
        this.batchLimit = batchLimit;
    }

    public Integer getIsWhile() {
        return isWhile;
    }

    public void setIsWhile(Integer isWhile) {
        this.isWhile = isWhile;
    }

    public String getWhileRule() {
        return whileRule;
    }

    public void setWhileRule(String whileRule) {
        this.whileRule = whileRule;
    }

    public Integer getIsClean() {
        return isClean;
    }

    public void setIsClean(Integer isClean) {
        this.isClean = isClean;
    }

    public String getCleanRule() {
        return cleanRule;
    }

    public void setCleanRule(String cleanRule) {
        this.cleanRule = cleanRule;
    }

    public Integer getFieldUpper() {
        return fieldUpper;
    }

    public void setFieldUpper(Integer fieldUpper) {
        this.fieldUpper = fieldUpper;
    }

    public String getCron() {
        return cron;
    }

    public void setCron(String cron) {
        try {
            new CronExpression(cron);
        } catch (Exception e) {
            throw new ServiceException("cron错误");
        }
        this.cron = cron;
    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public static boolean isValidCronExpression(String cronExpression) {
        try {
            new CronExpression(cronExpression);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
